<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="formDisabled">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row>
          <a-col :span="24">
            <a-form-model-item label="EC集团客户编码" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="customernum">
              <a-input v-model="model.customernum" placeholder="请输入EC集团客户编码"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="客户状态1-有效2-冻结，暂停使用3-无效" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="customerstatus">
              <a-input v-model="model.customerstatus" placeholder="请输入客户状态1-有效2-冻结，暂停使用3-无效"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="集团客户名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="customername">
              <a-input v-model="model.customername" placeholder="请输入集团客户名称"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="集团客户归属省代码" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="companyid">
              <a-input v-model="model.companyid" placeholder="请输入集团客户归属省代码"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="集团客户归属地市编码" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="location">
              <a-input v-model="model.location" placeholder="请输入集团客户归属地市编码"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="集团客户地址" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="customerlocation">
              <a-input v-model="model.customerlocation" placeholder="请输入集团客户地址"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="客户来源 hedun-和盾 bboss-BBOSS probation-试用表单" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="customersource">
              <a-input v-model="model.customersource" placeholder="请输入客户来源 hedun-和盾 bboss-BBOSS probation-试用表单"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="行业类别参考《一级BBOSS系统通用枚举值规范v1.2》的行业编码" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="industryid">
              <a-input v-model="model.industryid" placeholder="请输入行业类别参考《一级BBOSS系统通用枚举值规范v1.2》的行业编码"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="客户经理姓名" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="staffname">
              <a-input v-model="model.staffname" placeholder="请输入客户经理姓名"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="客户经理电话" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="staffphone">
              <a-input v-model="model.staffphone" placeholder="请输入客户经理电话"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="客户经理工号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="staffnumber">
              <a-input v-model="model.staffnumber" placeholder="请输入客户经理工号"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="客户服务等级 1-金牌级 2-银牌级 3-铜牌级 4-标准级" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="customerservlevel">
              <a-input v-model="model.customerservlevel" placeholder="请输入客户服务等级 1-金牌级 2-银牌级 3-铜牌级 4-标准级"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="客户联系电话【只允许手机号码】" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="customerphone">
              <a-input v-model="model.customerphone" placeholder="请输入客户联系电话【只允许手机号码】"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="客户联系邮件" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="costomeremail">
              <a-input v-model="model.costomeremail" placeholder="请输入客户联系邮件"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="告警通知方式1-短信2-邮件3-短信+邮件4-电话" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="costomercontact">
              <a-input v-model="model.costomercontact" placeholder="请输入告警通知方式1-短信2-邮件3-短信+邮件4-电话"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="集中抗D同步标记0-未同步（默认）5-同步中（插入同步任务表）1-同步确认中3-同步成功（正常状态）4-同步失败2-已修改，未同步（WEB端修改后）" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="syncflag">
              <a-input v-model="model.syncflag" placeholder="请输入集中抗D同步标记0-未同步（默认）5-同步中（插入同步任务表）1-同步确认中3-同步成功（正常状态）4-同步失败2-已修改，未同步（WEB端修改后）"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="同步返回信息" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="syncinfo">
              <a-input v-model="model.syncinfo" placeholder="请输入同步返回信息"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="负责人" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="header">
              <a-input v-model="model.header" placeholder="请输入负责人"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="创建时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="createdatetime">
              <j-date placeholder="请选择创建时间" v-model="model.createdatetime"  style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="最后修改时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="updatedatetime">
              <j-date placeholder="请选择最后修改时间" v-model="model.updatedatetime"  style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="0 - 正式，1 - 试用" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="customertype">
              <a-input v-model="model.customertype" placeholder="请输入0 - 正式，1 - 试用"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="开通状态 1、未开通，待补齐企业信息；2、已开通" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="openstatus">
              <a-input-number v-model="model.openstatus" placeholder="请输入开通状态 1、未开通，待补齐企业信息；2、已开通" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="真实客户编码" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="realcustomernum">
              <a-input v-model="model.realcustomernum" placeholder="请输入真实客户编码"  ></a-input>
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </j-form-container>
  </a-spin>
</template>

<script>

  import { httpAction, getAction } from '@/api/manage'
  import { validateDuplicateValue } from '@/utils/util'

  export default {
    name: 'BizOrgInfoForm',
    components: {
    },
    props: {
      //表单禁用
      disabled: {
        type: Boolean,
        default: false,
        required: false
      }
    },
    data () {
      return {
        model:{
         },
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        validatorRules: {
           customernum: [
              { required: true, message: '请输入EC集团客户编码!'},
           ],
           customerstatus: [
              { required: true, message: '请输入客户状态1-有效2-冻结，暂停使用3-无效!'},
           ],
           customername: [
              { required: true, message: '请输入集团客户名称!'},
           ],
           companyid: [
              { required: true, message: '请输入集团客户归属省代码!'},
           ],
           customertype: [
              { required: true, message: '请输入0 - 正式，1 - 试用!'},
           ],
        },
        url: {
          add: "/bizorginfo/bizOrgInfo/add",
          edit: "/bizorginfo/bizOrgInfo/edit",
          queryById: "/bizorginfo/bizOrgInfo/queryById"
        }
      }
    },
    computed: {
      formDisabled(){
        return this.disabled
      },
    },
    created () {
       //备份model原始值
      this.modelDefault = JSON.parse(JSON.stringify(this.model));
    },
    methods: {
      add () {
        this.edit(this.modelDefault);
      },
      edit (record) {
        this.model = Object.assign({}, record);
        this.visible = true;
      },
      submitForm () {
        const that = this;
        // 触发表单验证
        this.$refs.form.validate(valid => {
          if (valid) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            httpAction(httpurl,this.model,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
            })
          }
         
        })
      },
    }
  }
</script>